/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prototype.vaadin;

/**
 *
 * @author zineddine
 */
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 *
 * @author zineddine
 */

public class JobThread implements Callable<ConcurrentHashMap<String,String>> {
    private ConcurrentHashMap<String,String> concurrentMap = null;
    private String lienPage=null; 
    private Document  sf_page=null;
    private ConcurrentHashMap<String,String> mapPrincipale=null;
    
    public JobThread(String lienPage) {
        this.lienPage = lienPage;
        
    }
 
    
 
    @Override
    public ConcurrentHashMap<String,String>  call() throws Exception {
        concurrentMap = new ConcurrentHashMap<String,String>();
        sf_page = Jsoup.connect(lienPage).timeout(0).get();
	Element resultat = sf_page.getElementById("result_data");
	Elements links = resultat.getElementsByTag("a");
		
	for (Element link : links) {
            String linkHref = link.attr("href");
            String linkText = link.text();	 
         
            concurrentMap.put(linkText, linkHref);            	
	 }
        return concurrentMap;
       
    }
    
   
}
